import { defineStore } from 'pinia';
import type { RouteRecordNormalized } from 'vue-router';
import defaultSettings from '@/config/settings.json';
import { AppState } from '@/types'
import { getStorage, setStorage } from '@/utils/tools'
import { getEnumApi,getSystemInfo } from '@/api/common'


export const configStore = defineStore({
  id: 'app-config',
  state: () => ({
    pageLimit:  getStorage('config_page_limit'),
    enum:  getStorage('enum'),
    systemInfo:  getStorage('system_info'),
  }),
  actions: {
    setPageLimit(value: any) {
      setStorage('config_page_limit',value);
      this.pageLimit = value
    },
    async setSystemInfo(){
      try {
        const { data }: any = await getSystemInfo()
        setStorage('system_info',data);
        this.systemInfo = data
        return data
      } catch (e) {
        return false;
      }
    },
    async setEnum(){
      try {
        const { data }: any = await getEnumApi()
        setStorage('enum',data);
        return data
      } catch (e) {
        return false;
      }
    },
    getEnumItem(itemKey:any): any {
      return this.enum[itemKey]
    },
  },
  getters: {
    getPageLimit(): any {
      return this.pageLimit == null ? 20 : this.pageLimit
    },
    getEnum(): any {
      return this.enum
    },
    getSystemInfo(): any {
      return this.systemInfo
    },
  }
})


export default configStore;